<template>
	<barLayout navTitle="活动列表" isBack :showHomeIcon="false">
		<view class="scoreList flex-main">
			<view class="main">
				<view class="title">参与记录</view>
				<view v-if="list.length">
					<view v-for="(item, index) in list" :key="index" class="card" @click="toDetail(item)">
						<view class="time">
							<view class="clockBg"><image src="https://edu.c-eplus.com/activityfiles/miniapp/static/image/clock.png" class="clock"></image></view>
							<view class="label">{{ timeFormate(item.timeSequence, '001') || '--' }}</view>
						</view>

						<view class="project">
							<view class="project-item">
								<view>项目</view>
								<view class="item-text">{{ item.sportName || '--' }}</view>
							</view>
							<view class="project-item">
								<view>次数</view>
								<view class="item-text">{{ item.sportResultShow }}</view>
							</view>
							<view class="project-item">
								<view>得分</view>
								<view class="item-text">
									{{ Number(item.sportScore) ? item.sportScore : '--' }}
									<text class="unit">{{ Number(item.sportScore) ? '分' : '' }}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view v-else class="noData">
					<image src="https://edu.c-eplus.com/activityfiles/miniapp/static/image/noData.png" class="noDataImg"></image>
					<text class="nodataText">暂无体验记录~</text>
				</view>
			</view>
		</view>
	</barLayout>
</template>

<script>
import barLayout from '@/pages/layout/barLayout.vue';
import { getScorelList } from '@/api/activity.js';
import { timeFormate } from '@/utils/util.js';
export default {
	components: {
		barLayout
	},
	data() {
		return {
			list: [],
			dcActivityId: ''
		};
	},
	onLoad(params) {
		if (params && params.dcActivityId) {
			this.dcActivityId = params.dcActivityId;
			this.getData();
		}
	},
	onPullDownRefresh() {
		this.list = [];
		setTimeout(() => {
			this.getData();
		}, 1000);
	},
	methods: {
		timeFormate,
		getData() {
			getScorelList({
				dcActivityId: this.dcActivityId
			}).then(res => {
				let { data, success, errMsg } = res.data;
				if (success) {
					if (data && data.trainResults.length) {
						this.list = data.trainResults || [];
					}
				} else {
					uni.showModal({
						content: errMsg,
						showCancel: false
					});
				}
				uni.stopPullDownRefresh();
			});
		},
		toDetail(project) {
			uni.navigateTo({
				url: '/pages/activity/scoreDetail?project=' + JSON.stringify(project)
			});
		}
	}
};
</script>

<style></style>
